package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.Industry;
import com.ruoyi.finance.service.IIndustryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行业分类Controller
 * 
 * @author 李伟
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/finance/industry")
public class IndustryController extends BaseController
{
    @Autowired
    private IIndustryService industryService;

    /**
     * 查询行业分类列表
     */
    @PreAuthorize("@ss.hasPermi('finance:industry:list')")
    @GetMapping("/list")
    public TableDataInfo list(Industry industry)
    {
        startPage();
        List<Industry> list = industryService.selectIndustryList(industry);
        return getDataTable(list);
    }
    @GetMapping("/getindustry")
    public TableDataInfo getindustry()
    {
        List<Industry> list = industryService.getindustry();
        return getDataTable(list);
    }

    /**
     * 导出行业分类列表
     */
    @PreAuthorize("@ss.hasPermi('finance:industry:export')")
    @Log(title = "行业分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Industry industry)
    {
        List<Industry> list = industryService.selectIndustryList(industry);
        ExcelUtil<Industry> util = new ExcelUtil<Industry>(Industry.class);
        util.exportExcel(response, list, "行业分类数据");
    }

    /**
     * 获取行业分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:industry:query')")
    @GetMapping(value = "/{industryId}")
    public AjaxResult getInfo(@PathVariable("industryId") Long industryId)
    {
        return success(industryService.selectIndustryByIndustryId(industryId));
    }

    /**
     * 新增行业分类
     */
    @PreAuthorize("@ss.hasPermi('finance:industry:add')")
    @Log(title = "行业分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated Industry industry)
    {
        return toAjax(industryService.insertIndustry(industry));
    }

    /**
     * 修改行业分类
     */
    @PreAuthorize("@ss.hasPermi('finance:industry:edit')")
    @Log(title = "行业分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Industry industry)
    {
        return toAjax(industryService.updateIndustry(industry));
    }

    /**
     * 删除行业分类
     */
    @PreAuthorize("@ss.hasPermi('finance:industry:remove')")
    @Log(title = "行业分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{industryIds}")
    public AjaxResult remove(@PathVariable Long[] industryIds)
    {
        return toAjax(industryService.deleteIndustryByIndustryIds(industryIds));
    }
}
